package com.china08.yxyapi.api.manage.tec.teaching.lecture.res;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.res.YxyResBookContents;
import com.china08.yxyapi.repository.db.YxyResBookContentsRepository;

/***
 * 根据目录获得知识点列表
 * 
 * @author renruihu
 *
 */
@CrossOrigin
@RestController
public class LectureResKnowController extends YxyApiBaseController {

    @Autowired
    private YxyResBookContentsRepository yrbcr;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/lecture/res/know/bookcontent/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object process(HttpServletRequest request, HttpServletResponse response,
            @PathVariable(value = "id") String id) {
        RespModel respModel = new RespModel();
        // ## 资源目录
        YxyResBookContents bookContents = yrbcr.findById(id);
        List<String> idsList = new ArrayList<String>();
        // 找到知识点All
        String[] arras = StringUtils.split(bookContents.getAllKnow(), ",");
        if (arras.length > 0) {
            idsList = Arrays.asList(arras);
        }
        respModel.ids = idsList;
        return respModel;
    }

    protected class RespModel {
        public List<String> ids;
    }

}
